﻿# Create your views here.
# -*- coding: utf-8 -*

from django.shortcuts import render_to_response
from django.template  import loader, Context 
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render_to_response
from show.models import *
from datetime import datetime
from django.db import connection
from django.db.models import Q 
from account.views import siteuser_login_required

#主页的函数

def index(request):
    posts = BlogPosts.objects.all().order_by('-id')[:3]
    t = loader.get_template("index.html")
    c = Context({ 'posts':posts })
    return HttpResponse(t.render(c))

#blog页面的显示  
@siteuser_login_required  
def blog(request):
    header_title = 'Blog Page'
    header_val = 'Bolg Page With Sidebar'
    return render_to_response('blog.html',{'title':header_title,'val':header_val})

#search页面的控制函数   
@siteuser_login_required 
def search(request):
    header_title = 'Search Page'
    header_val = 'Search Page With Sidebar'
    return render_to_response('search.html',{'title':header_title,'val':header_val})

#blog详细显示    
@siteuser_login_required
def blog_details(request):
    header_title = 'Blog_details Page'
    header_val = 'Blog_details Page With Sidebar'
    return render_to_response('blog_details.html',{'title':header_title,'val':header_val})

#信息发布页面的详细显示
@siteuser_login_required
def Information(request,id):
    if id =='1':
        return render_to_response('nodebook_infor.html')
    elif id =='2':
        return render_to_response('nodebook_infor.html')
    elif id =='3':
        return render_to_response('nodebook_infor.html')
    elif id =='4':
        return render_to_response('nodebook_infor.html')
    elif id =='5':
        return render_to_response('nodebook_infor.html')
    else:
        return render_to_response('nodebook_infor.html')



#news页面显示    
@siteuser_login_required
def news(request):
    print 'news page'
    header_title = 'News Page'
    header_val = 'News Page With Sidebar'
    titles = []
    urls = []
    more = []
    content = []
    action = '/newsearch'
    if 'search' in request.POST and request.POST["search"] != '' :
        search = request.POST["search"]
        print search,'search'
        lines = Newsbase.objects.filter(Q(content__contains = search)|Q(title__contains = search))
        totle = len(lines)
        print '查询的总数是',totle

        if totle>=4:
            for line in lines[0:4]:
                titles.append(line.title)
                urls.append(line.image)
                more.append(line.id)
                content.append(line.content[0:45])
        else:
            for line in lines:
                titles.append(line.title)
                urls.append(line.image)
                more.append(line.id)
                content.append(line.content[0:45])
        return render_to_response('news.html',{'title':header_title,'val':header_val,'image':urls,'titles':titles,'content':content,'id':more,'action':action})
    else:
        lines = Newsbase.objects.order_by('pub_time')[0:4]
        for line in lines:
            titles.append(line.title)
            urls.append(line.image)
            more.append(line.id)
            content.append(line.content[0:45])
        return render_to_response('news.html',{'title':header_title,'val':header_val,'image':urls,'titles':titles,'content':content,'id':more,'action':action})




@siteuser_login_required
def save_news(request):
    title = request.POST.get('title')
    author = request.POST.get('author')
    content = request.POST.get('content')
    now = datetime.now()
    p = Newsbase(
        title = title,\
        author = author,\
        pub_time = now,\
        content = content
    )
    p.save()
    return render_to_response('index.html')

@siteuser_login_required
def pub_news(request):

    return render_to_response('pub_news.html')

@siteuser_login_required
def newsearch(request):

    return render_to_response('index.html')
    
#新闻页面的详细显示函数   
@siteuser_login_required 
def news_details(request,id):
    header_title = 'News Page'
    header_val = 'News Page With Sidebar'
    action = '/newsearch'
    num_id = int(id)-1
    print num_id,'idnum'
    line = Newsbase.objects.order_by('-id')[num_id]
    titles = line.title
    image = line.image
    time = line.pub_time
    content = line.content

    if line.author:
        author = line.author
    else:
        author = '未知作者'
    return render_to_response('news_details.html',{'title':header_title,'val':header_val,'titles':titles,'time':time,'image':image,'author':author,'content':content,'action':action})



#笔记本页面的显示
@siteuser_login_required
def notebooks(request):
    header_title = 'Notebook Page'
    header_val = 'Notebook Page With Sidebar'
    if 'search' in request.POST:
        print request.POST['search']
        return render_to_response('nodebooksearch.html')
    else :
        items = []
        name = []
        url = []
        image = []
        action = '/nodebooksearch'
        lines = nodebook.objects.order_by('id')[0:6]
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.ncrl) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.yprl) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.xspcc)
            items.append(item)
    return render_to_response('notebook.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})


@siteuser_login_required
def nodebooksearch(request):

    return render_to_response('nodebooksearch.html')


@siteuser_login_required
def nodebook_details(request,id):
    header_title = 'Notebook Details Page'
    header_val = 'Notebook Details Page With Sidebar'
    action = '/nodebooksearch'
    print id , 'id'
    query = int(id)-1
    line = nodebook.objects.all().order_by('id')[query]
    print line.id,'line'
    item = get_nodebook_items(line)
    return render_to_response('nodebook_result.html',{'item':item,'title':header_title,'val':header_val,'action':action})


@siteuser_login_required
def nodebook_pinpai(request,type):
    header_title = 'Notebook Page'
    header_val = 'Notebook Page With Sidebar'
    print type,'type'
    lines = nodebook.objects.all().filter(Q(name__contains = type))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines:
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.ncrl) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.yprl) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.xspcc)
            items.append(item)
    else :
        pass
    return render_to_response('notebook.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})


@siteuser_login_required
def nodebook_price(request,price):
    header_title = 'Notebook Page'
    header_val = 'Notebook Page With Sidebar'
    print price,'price'
    if price == '5000':
        lines = nodebook.objects.filter(price__range=(3000,5000))
    elif price =='7000':
        lines = nodebook.objects.filter(price__range=(5000,7000))
    elif price =='9000':
        lines = nodebook.objects.filter(price__range=(7000,9000))
    elif price =='10000':
        lines = nodebook.objects.filter(price__range=(9000,10000))
    elif price =='20000':
        lines = nodebook.objects.filter(price>10000)
    else:
        lines = nodebook.objects.filter(price__range=(0,3000))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines:
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.ncrl) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.yprl) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.xspcc)
            items.append(item)
    else :
        pass
    return render_to_response('notebook.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})

@siteuser_login_required
def nodebook_pinmu(request,num):
    header_title = 'Notebook Page'
    header_val = 'Notebook Page With Sidebar'
    print num,'num'
    if num =='11':
        lines = nodebook.objects.all().filter(Q(xspcc__contains = num))
    elif num =='12':
        lines = nodebook.objects.all().filter(Q(xspcc__contains = num))
    elif num =='13':
        lines = nodebook.objects.all().filter(Q(xspcc__contains = num))
    elif num =='14':
        lines = nodebook.objects.all().filter(Q(xspcc__contains = num))
    elif num =='15':
        lines = nodebook.objects.all().filter(Q(xspcc__contains = num))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines:
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.ncrl) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.yprl) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.xspcc)
            items.append(item)
    else :
        pass
    return render_to_response('notebook.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})


@siteuser_login_required
def nodebook_core(request,core):
    header_title = 'Notebook Page'
    header_val = 'Notebook Page With Sidebar'
    print core,'core'
    lines = nodebook.objects.all().filter(Q(clqxl__contains = core))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines:
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.ncrl) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.yprl) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.xspcc)
            items.append(item)
    else :
        pass
    return render_to_response('notebook.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})


@siteuser_login_required
def nodebook_disk(request,disk):
    header_title = 'Notebook Page'
    header_val = 'Notebook Page With Sidebar'
    print num,'type'
    lines = nodebook.objects.all().filter(Q(xspcc__contains = num))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines:
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.ncrl) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.yprl) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.xspcc)
            items.append(item)
    else :
        pass
    return render_to_response('notebook.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})


@siteuser_login_required
def nodebook_disksize(request,disksize):
    header_title = 'Notebook Page'
    header_val = 'Notebook Page With Sidebar'
    print disksize,'disksize'
    if disksize=='250以下':
        lines = nodebook.objects.all().filter(Q(yprl__lt = 250))
    elif disksize == '250':
        lines = nodebook.objects.all().filter(Q(yprl__range = (250,320)))
    elif disksize == '320':
        lines = nodebook.objects.all().filter(Q(yprl__range = (320,500)))
    elif disksize == '500':
        lines = nodebook.objects.all().filter(Q(yprl__range = (500,1000)))
    elif disksize == '1024':
        lines = nodebook.objects.all().filter(Q(yprl__range = (1000,5000)))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines:
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.ncrl) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.yprl) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.xspcc)
            items.append(item)
    else :
        pass
    return render_to_response('notebook.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})


@siteuser_login_required
def nodebook_xianka(request,type):
    header_title = 'Notebook Page'
    header_val = 'Notebook Page With Sidebar'
    print type,'type'
    lines = nodebook.objects.all().filter(Q(xklx__contains = type))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines:
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.ncrl) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.yprl) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.xspcc)
            items.append(item)
    else :
        pass
    return render_to_response('notebook.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})


@siteuser_login_required
def nodebook_memerysize(request,size):
    header_title = 'Notebook Page'
    header_val = 'Notebook Page With Sidebar'
    print size,'size'
    if size=='1':
        lines = nodebook.objects.all().filter(Q(ncrl = int(size)))
    elif size=='2':
        lines = nodebook.objects.all().filter(Q(ncrl = int(size)))
    elif size=='3':
        lines = nodebook.objects.all().filter(Q(ncrl = int(size)))
    elif size=='4':
        lines = nodebook.objects.all().filter(Q(ncrl = int(size)))
    elif size=='6':
        lines = nodebook.objects.all().filter(Q(ncrl = int(size)))
    elif size=='8':
        lines = nodebook.objects.all().filter(Q(ncrl = int(size)))
    elif size=='12':
        lines = nodebook.objects.all().filter(Q(ncrl__gte = int(size)))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines :
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.ncrl) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.yprl) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.xspcc)
            items.append(item)
    else :
        pass
    return render_to_response('notebook.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})
#台式机页面的显示
@siteuser_login_required    
def desktops(request):
    print request,'request'
    if 'search' in request.POST:
        print request.POST['search']
        return render_to_response('desktopsearch.html')
    else :
        header_title = 'Desktop Page'
        header_val = 'Desktop Page With Sidebar'
        items = []
        name = []
        id = []
        image = []
        action = '/desktopsearch'
        lines = desktop.objects.order_by('id')[0:4]
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            id.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.memsize) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.disksize) + "GB"
            item.append(disksize)
            item.append(u"CPU系列： "+line.cpusir)
            items.append(item)

        return render_to_response('desktop.html',{'title':header_title,'val':header_val,'id':id,'name':name,'image':image,'action':action,'items':items})

@siteuser_login_required      
def desktop_memerysize(request,size):
    memoryview = int(size)
    print memoryview , 'memory'
    lines = desktop.objects.all().filter(memsize = memoryview)
    items = []
    name = []
    id = []
    image = []
    for line in lines:
        item = []
        name.append(line.name)
        image.append(line.image)
        id.append(line.id)
        price = "参考价格：" + str(line.price)+"元"
        item.append(price)
        memsize = "内存容量：" + str(line.memsize) +"GB"
        item.append(memsize)
        disksize = "硬盘容量：" + str(line.disksize) + "GB"
        item.append(disksize)
        item.append(u"CPU系列： "+line.cpusir)
        items.append(item)

    return render_to_response('desktop_result.html',{'id':id,'name':name,'image':image,'items':items})
    
@siteuser_login_required      
def desktop_pinpai(request,type):
    #print type ,'type'
    type = type
    lines = desktop.objects.all().filter(Q(name__contains = type))
    #print lines,'linesc'
    items = []
    name = []
    id = []
    image = []
    for line in lines:
        item = []
        name.append(line.name)
        image.append(line.image)
        id.append(line.id)
        price = "参考价格：" + str(line.price)+"元"
        item.append(price)
        memsize = "内存容量：" + str(line.memsize) +"GB"
        item.append(memsize)
        disksize = "硬盘容量：" + str(line.disksize) + "GB"
        item.append(disksize)
        item.append(u"CPU系列： "+line.cpusir)
        items.append(item)
    return render_to_response('desktop_result.html',{'id':id,'name':name,'image':image,'items':items})
    
@siteuser_login_required      
def desktop_price(request,price):
        print price
        if price == '5000':
            lines = desktop.objects.filter(price__range=(3000,5000))
        elif price =='7000':
            lines = desktop.objects.filter(price__range=(5000,7000))
        elif price =='9000':
            lines = desktop.objects.filter(price__range=(7000,9000))
        elif price =='10000':
            lines = desktop.objects.filter(price__range=(9000,10000))
        elif price =='20000':
            lines = desktop.objects.filter(price>10000)
        else:
            lines = desktop.objects.filter(price__range=(0,3000))
        items = []
        name = []
        id = []
        image = []
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            id.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.memsize) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.disksize) + "GB"
            item.append(disksize)
            item.append(u"CPU系列： "+line.cpusir)
            items.append(item)
        return render_to_response('desktop_result.html',{'id':id,'name':name,'image':image,'items':items})
    
@siteuser_login_required      
def desktop_core(request,core):
    """
    这是台式机的cpu类型的一个处理函数，主要是找出所有与之符合条件的电脑
    """
    lines = desktop.objects.all().filter(Q(cputype__contains = core))
    items = []
    name = []
    id = []
    image = []
    for line in lines:
        item = []
        name.append(line.name)
        image.append(line.image)
        id.append(line.id)
        price = "参考价格：" + str(line.price)+"元"
        item.append(price)
        memsize = "内存容量：" + str(line.memsize) +"GB"
        item.append(memsize)
        disksize = "硬盘容量：" + str(line.disksize) + "GB"
        item.append(disksize)
        item.append(u"CPU系列： "+line.cpusir)
        items.append(item)
    return render_to_response('desktop_result.html',{'id':id,'name':name,'image':image,'items':items})
    
@siteuser_login_required
def desktop_disk(request,disk):
    disk = str(disk)
    print disk,'disk'
    lines = desktop.objects.all().filter(Q(diskdis__contains = disk))
    items = []
    name = []
    id = []
    image = []
    for line in lines:
        item = []
        name.append(line.name)
        image.append(line.image)
        id.append(line.id)
        price = "参考价格：" + str(line.price)+"元"
        item.append(price)
        memsize = "内存容量：" + str(line.memsize) +"GB"
        item.append(memsize)
        disksize = "硬盘容量：" + str(line.disksize) + "GB"
        item.append(disksize)
        item.append(u"CPU系列： "+line.cpusir)
        items.append(item)
    return render_to_response('desktop_result.html',{'id':id,'name':name,'image':image,'items':items})
    
@siteuser_login_required      
def desktop_disksize(request,disksize):
    lines = desktop.objects.all().filter(disksize = disksize)
    items = []
    name = []
    id = []
    image = []
    for line in lines:
        item = []
        name.append(line.name)
        image.append(line.image)
        id.append(line.id)
        price = "参考价格：" + str(line.price)+"元"
        item.append(price)
        memsize = "内存容量：" + str(line.memsize) +"GB"
        item.append(memsize)
        disksize = "硬盘容量：" + str(line.disksize) + "GB"
        item.append(disksize)
        item.append(u"CPU系列： "+line.cpusir)
        items.append(item)
    return render_to_response('desktop_result.html',{'id':id,'name':name,'image':image,'items':items})
@siteuser_login_required      
def desktop_xianka(request,type):
    lines = desktop.objects.all().filter(Q(graphictype__contains = type))
    items = []
    name = []
    id = []
    image = []
    for line in lines:
        item = []
        name.append(line.name)
        image.append(line.image)
        id.append(line.id)
        price = "参考价格：" + str(line.price)+"元"
        item.append(price)
        memsize = "内存容量：" + str(line.memsize) +"GB"
        item.append(memsize)
        disksize = "硬盘容量：" + str(line.disksize) + "GB"
        item.append(disksize)
        item.append(u"CPU系列： "+line.cpusir)
        items.append(item)
    return render_to_response('desktop_result.html',{'id':id,'name':name,'image':image,'items':items})
@siteuser_login_required      
def desktop_scarch(request):

    return render_to_response('desktop_scarch.html')    

    
@siteuser_login_required    
def desktop_details(request,id):
    header_title = 'Desktop details'
    header_val = 'Desktop details  Page With Sidebar'
    action = '/desktopsearch'
    num_id = int(id)-1
    line = desktop.objects.order_by('-id')[num_id]
    item = get_desktop_items(line)
    return render_to_response('desktop_details.html',{'title':header_title,'val':header_val,'item':item,'action':action})

    
@siteuser_login_required   
def pad(request):
    header_title = 'Pad Page'
    header_val = 'Pad Page With Sidebar'
    return render_to_response('pad.html',{'title':header_title,'val':header_val})   

    
    
#超级本的页面的显示  
@siteuser_login_required  
def ultra(request):
    header_title = 'Ultra Page'
    header_val = 'Ultra Page With Sidebar'
    if 'search' in request.POST:
        print request.POST['search']
        return render_to_response('urtalbooksearch.html')
    else :
        items = []
        name = []
        url = []
        image = []
        action = '/urtalbooksearch'
        lines = ultrebook.objects.order_by('id')[0:6]
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.memsize) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.disksize) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.screensize)
            items.append(item)
    return render_to_response('ultra.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})

def urtalbooksearch(request):

    return render_to_response('urtalbooksearch.html')

#超级本的页面的显示
@siteuser_login_required
def urtalbook_details(request,id):
    header_title = 'Ultra Page'
    header_val = 'Ultra Page With Sidebar'
    action = '/urtalbooksearch'
    print id , 'id'
    query = int(id)-1
    line = ultrebook.objects.all().order_by('id')[query]
    print line.id,'line'
    item = get_urtalbook_items(line)
    print item,'item'
    return render_to_response('urtalbook_result.html',{'item':item,'title':header_title,'val':header_val,'action':action})

#超级本的页面的显示
@siteuser_login_required
def urtalbook_pinpai(request,type):
    header_title = 'Ultra Page'
    header_val = 'Ultra Page With Sidebar'
    print type,'type'
    items = []
    name = []
    url = []
    image = []
    action = '/urtalbooksearch'
    lines = ultrebook.objects.all().filter(Q(name__contains = type))
    for line in lines:
        item = []
        name.append(line.name)
        image.append(line.image)
        url.append(line.id)
        price = "参考价格：" + str(line.price)+"元"
        item.append(price)
        memsize = "内存容量：" + str(line.memsize) +"GB"
        item.append(memsize)
        disksize = "硬盘容量：" + str(line.disksize) + "GB"
        item.append(disksize)
        item.append(u"屏幕尺寸： "+line.screensize)
        items.append(item)
    return render_to_response('ultra.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})

#超级本的页面的显示
@siteuser_login_required
def urtalbook_price(request,price):
    header_title = 'Ultra Page'
    header_val = 'Ultra Page With Sidebar'
    print price,'price'
    if price == '5000':
        lines = ultrebook.objects.filter(price__range=(3000,5000))
    elif price =='7000':
        lines = ultrebook.objects.filter(price__range=(5000,7000))
    elif price =='9000':
        lines = ultrebook.objects.filter(price__range=(7000,9000))
    elif price =='10000':
        lines = ultrebook.objects.filter(price__range=(9000,10000))
    elif price =='20000':
        lines = ultrebook.objects.filter(price>10000)
    else:
        lines = ultrebook.objects.filter(price__range=(0,3000))
    items = []
    name = []
    url = []
    image = []
    action = '/urtalbooksearch'
    for line in lines:
        item = []
        name.append(line.name)
        image.append(line.image)
        url.append(line.id)
        price = "参考价格：" + str(line.price)+"元"
        item.append(price)
        memsize = "内存容量：" + str(line.memsize) +"GB"
        item.append(memsize)
        disksize = "硬盘容量：" + str(line.disksize) + "GB"
        item.append(disksize)
        item.append(u"屏幕尺寸： "+line.screensize)
        items.append(item)
    return render_to_response('ultra.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})

#超级本的页面的显示
@siteuser_login_required
def urtalbook_pinmu(request,num):
    header_title = 'Ultra Page'
    header_val = 'Ultra Page With Sidebar'
    print num,'num'
    if num =='11':
        lines = ultrebook.objects.all().filter(Q(screensize__contains = num))
    elif num =='12':
        lines = ultrebook.objects.all().filter(Q(screensize__contains = num))
    elif num =='13':
        lines = ultrebook.objects.all().filter(Q(screensize__contains = num))
    elif num =='14':
        lines = ultrebook.objects.all().filter(Q(screensize__contains = num))
    elif num =='15':
        lines = ultrebook.objects.all().filter(Q(screensize__contains = num))
    items = []
    name = []
    url = []
    image = []
    action = '/urtalbooksearch'
    for line in lines:
        item = []
        name.append(line.name)
        image.append(line.image)
        url.append(line.id)
        price = "参考价格：" + str(line.price)+"元"
        item.append(price)
        memsize = "内存容量：" + str(line.memsize) +"GB"
        item.append(memsize)
        disksize = "硬盘容量：" + str(line.disksize) + "GB"
        item.append(disksize)
        item.append(u"屏幕尺寸： "+line.screensize)
        items.append(item)
    return render_to_response('ultra.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})

#超级本的页面的显示
@siteuser_login_required
def urtalbook_core(request,core):
    header_title = 'Ultra Page'
    header_val = 'Ultra Page With Sidebar'
    print core,'core'
    lines = ultrebook.objects.all().filter(Q(cputype__contains = core))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines:
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.memsize) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.disksize) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.screensize)
            items.append(item)
    else :
        pass
    return render_to_response('ultra.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})

#超级本的页面的显示
@siteuser_login_required
def urtalbook_disk(request,disk):
    header_title = 'Ultra Page'
    header_val = 'Ultra Page With Sidebar'
    print disk,'disk'
    lines = ultrebook.objects.all().filter(Q(diskdis__contains = disk))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines:
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.memsize) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.disksize) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.screensize)
            items.append(item)
    else :
        pass
    return render_to_response('ultra.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})


#超级本的页面的显示
@siteuser_login_required
def urtalbook_high(request,high):
    header_title = 'Ultra Page'
    header_val = 'Ultra Page With Sidebar'
    print high,'high'
    if high =='20':
        lines = ultrebook.objects.all().filter(Q(high__range =(19,20)))
    elif high=='19':
        lines = ultrebook.objects.all().filter(Q(high__range =(17,19)))
    elif high=='17':
        lines = ultrebook.objects.all().filter(Q(high__range =(15,17)))
    elif high=='15':
        lines = ultrebook.objects.all().filter(Q(high__lt =15))
    else:
        lines = ultrebook.objects.all().filter(Q(high__lt =15))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines:
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.memsize) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.disksize) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.screensize)
            items.append(item)
    else :
        pass
    return render_to_response('ultra.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})


#超级本的页面的显示
@siteuser_login_required
def urtalbook_weight(request,weight):
    header_title = 'Ultra Page'
    header_val = 'Ultra Page With Sidebar'
    print weight,'weight'
    if weight =='2':
        lines = ultrebook.objects.all().filter(Q(weight__lt =120))
    elif weight=='3':
        lines = ultrebook.objects.all().filter(Q(weight__range =(120,130)))
    elif weight=='4':
        lines = ultrebook.objects.all().filter(Q(weight__range =(130,140)))
    elif weight=='5':
        lines = ultrebook.objects.all().filter(Q(weight__range =(140,150)))
    elif weight=='6':
        lines = ultrebook.objects.all().filter(Q(weight__range =(150,200)))
    elif weight=='7':
        lines = ultrebook.objects.all().filter(Q(weight__range =(200,250)))
    else:
        lines = ultrebook.objects.all().filter(Q(weight__gt =250))
    items = []
    name = []
    url = []
    image = []
    action = '/nodebooksearch'
    if lines:
        for line in lines:
            item = []
            name.append(line.name)
            image.append(line.image)
            url.append(line.id)
            price = "参考价格：" + str(line.price)+"元"
            item.append(price)
            memsize = "内存容量：" + str(line.memsize) +"GB"
            item.append(memsize)
            disksize = "硬盘容量：" + str(line.disksize) + "GB"
            item.append(disksize)
            item.append(u"屏幕尺寸： "+line.screensize)
            items.append(item)
    else :
        pass
    return render_to_response('ultra.html',{'title':header_title,'action':action,'val':header_val,'name':name,'url':url,'image':image,'items':items})

#一体机的页面的显示 
@siteuser_login_required   
def intm(request):
    header_title = 'Easy_pc Page'
    header_val = 'Easy_pc Page With Sidebar'
    return render_to_response('intm.html',{'title':header_title,'val':header_val})      

    
@siteuser_login_required   
def show_column(request):
    
    return render_to_response('show_column.html')  


    
@siteuser_login_required
def show_format(request,num):
    if num == '1':
        column = 1
        header_title = '1 Columns'
        header_val = 'show page with 1 columns'
    elif num == '2':
        column = 2
        header_title = '2 Columns'
        header_val = 'show page with 2 columns'
    elif num == '3':
        column = 3
        header_title = '3 Columns'
        header_val = 'show page with 3 columns'
    elif num == '4':
        column = 4
        header_title = '4 Columns'
        header_val = 'show page with 4 columns'
    else :
        column = 0
        header_title = 'none Columns'
        header_val = 'show page with none columns'
    
    return render_to_response('show_format.html',{'column':column,'title':header_title,'val':header_val})    

    
    
#联系页面的显示函数 
@siteuser_login_required   
def contact(request):
    header_title = 'Contact Page'
    header_val = 'Contact Page With Sidebar'
    return render_to_response('contact.html',{'title':header_title,'val':header_val})

#联系页面的显示函数
@siteuser_login_required
def sendme(request):
    assert(request.method=='POST' and request.is_ajax()==True)
    try:
        author = request.POST['name']
        email = request.POST['email']
        subject = request.POST['subject']
        message = request.POST['message']
        now = datetime.now()
        p = Message(
            author = author,\
            email = email,\
            subject = subject,\
            message = message,\
            sendtime = now,\
            issolve = 0
        )
        p.save()
        return HttpResponse('success')
    except:
        return HttpResponse('fail')



#电脑详细信息页面的显示函数 
@siteuser_login_required   
def details(request):
    header_title = 'Details Page'
    header_val = 'Details Page With Sidebar'
    #order = 
    #line = desktop.objects.filter( id = order)[0]
    line = nodebook.objects.order_by('id')[0]
    item = get_nodebook_items(line)
    #item = ['ffdfsdf','ffreyhhhhhh','yyyyyyyyy']
    print item,'item'
    item = []
    return render_to_response('details.html',{'title':header_title,'val':header_val,'item':item})

def get_nodebook_items(line):
    id = line.id
    name = line.name
    price = line.price
    pt = line.pt
    pp = line.pp
    czxt = line.czxt
    xh = line.xh
    clqxl = line.clqxl
    clqxh = line.clqxh
    clqzp = line.clqzp
    sjhc = line.sjhc
    ncrl = line.ncrl
    nclx = line.nclx
    yprl = line.yprl
    gqlx = line.gqlx
    xspcc = line.xspcc
    xspb = line.xspb
    xspfbl = line.xspfbl
    bgjs = line.bgjs
    xklx = line.xklx
    xkxp = line.xkxp
    xkrl = line.xkrl
    ypxt = line.ypxt
    ysq = line.ysq
    mkf = line.mkf
    sxt = line.sxt
    wxjyw = line.wxjyw
    jywlx = line.jywlx
    sjjk = line.sjjk
    spjk = line.spjk
    ypjk = line.ypjk
    ptjk = line.ptjk
    dkq = line.dkq
    dclx = line.dclx
    xhsj = line.xhsj
    wxcc = line.wxcc
    zl = line.zl
    #获取每一条信息的所有属性信息然后添加到item中
    item = []
    item.append(pt)
    item.append(pp)
    item.append(czxt)
    item.append(xh)
    item.append(clqxl)
    item.append(clqxh)
    item.append(clqzp)
    item.append(sjhc)
    item.append(ncrl)
    item.append(nclx)
    item.append(yprl)
    item.append(gqlx)
    item.append(xspcc)
    item.append(xspb)
    item.append(xspfbl)
    item.append(bgjs)
    item.append(xklx)
    item.append(xkxp)
    item.append(xkrl)
    item.append(ypxt)
    item.append(ysq)
    item.append(mkf)
    item.append(sxt)
    item.append(wxjyw)
    item.append(jywlx)
    item.append(sjjk)
    item.append(spjk)
    item.append(ypjk)
    item.append(ptjk)
    item.append(dkq)
    item.append(dclx)
    item.append(xhsj)
    item.append(wxcc)
    item.append(zl)
    return item
    
    
def get_desktop_items(line):
    item = []
    item.append(line.type)
    item.append(line.operation)
    item.append(line.mbchip)
    item.append(line.cpusir)
    item.append(line.cputype)
    item.append(line.cpufre)
    item.append(line.cpumax)
    item.append(line.bus)
    item.append(line.secmem)
    item.append(line.thimem)
    item.append(line.core)
    item.append(line.corenum)
    item.append(line.makesize)
    item.append(line.memsize)
    item.append(line.memtype)
    item.append(line.disksize)
    item.append(line.diskdis)
    item.append(line.cdromtype)
    item.append(line.cdromdis)
    item.append(line.graphictype)
    item.append(line.graphiccore)
    item.append(line.graphicmem)
    item.append(line.graphicdis)
    item.append(line.screensize)
    item.append(line.screenresolution)
    item.append(line.screendis)
    item.append(line.net)
    item.append(line.usbinterface)
    item.append(line.audiointerface)
    item.append(line.videointerface)
    item.append(line.netinterface)
    item.append(line.otherinterface)
    item.append(line.reader)
    item.append(line.power)
    item.append(line.chassistype)
    item.append(line.chassiscolor)
    return item


def get_urtalbook_items(line):
    item = []
    item.append(line.name)
    item.append(line.price)
    item.append(line.pubtime)
    item.append(line.type)
    item.append(line.pubfor)
    item.append(line.operation)
    item.append(line.mbchip)
    item.append(line.cpusir)
    item.append(line.cputype)
    item.append(line.cpumax)
    item.append(line.bus)
    item.append(line.thimem)
    item.append(line.core)
    item.append(line.gongyi)
    item.append(line.gonghao)
    item.append(line.memsize)
    item.append(line.memtype)
    item.append(line.disksize)
    item.append(line.diskdis)
    item.append(line.cdromtype)
    item.append(line.graphictype)
    item.append(line.graphicmem)
    item.append(line.screensize)
    item.append(line.screenratio)
    item.append(line.screenresolution)
    item.append(line.lcd)
    item.append(line.wireless)
    item.append(line.wire)
    item.append(line.shexiangtou)
    item.append(line.sound)
    item.append(line.mic)
    item.append(line.audiointerface)
    item.append(line.videointerface)
    item.append(line.datainterface)
    item.append(line.otherinterface)
    item.append(line.weight/100)
    item.append(line.power)
    item.append(line.length)
    item.append(line.wigth)
    item.append(line.high)
    return item
'''
 item = {}
    item['平台'] = pt
    item['品牌'] = pp
    item['操作系统'] = czxt
    item['型号'] = xh
    item['处理器系列'] = clqxl
    item['处理器型号'] = clqxh
    item['处理器主频'] = clqzp
    item['三级缓存'] = sjhc
    item['内存容量'] = ncrl
    item['内存类型'] = nclx
    item['硬盘容量'] = yprl
    item['光驱类型'] = gqlx
    item['显示屏屏尺'] = xspcc
    item['显示屏屏比'] = xspb
    item['显示屏分辨率'] = xspfbl
    item['背光技术'] = bgjs
    item['显卡类型'] = xklx
    item['显卡芯片'] = xkxp
    item['显卡容量'] = xkrl
    item['音频系统'] = ypxt
    item['扬声器'] = ysq
    item['麦克风'] = mkf
    item['摄像头'] = sxt
    item['无线局域网'] = wxjyw
    item['局域网描述'] = jywlx
    item['数据接口'] = sjjk
    item['视频接口'] = spjk
    item['音频接口'] = ypjk
    item['读卡器'] = ptjk
    item['其他接口'] = dkq
    item['电池类型'] = dclx
    item['续航时间'] = xhsj
    item['外形尺寸'] = wxcc
    item['重量'] = zl
'''    
    